import { jest } from '@jest/globals';
import { PromptManager } from '../../../src/core/PromptManager.mjs';

const { describe, test, expect, beforeEach } = await import('@jest/globals');

describe('PromptManager', () => {
  let promptManager;

  beforeEach(() => {
    promptManager = new PromptManager({
      systemPrompt: 'test system prompt'
    });
  });

  test('should throw error for invalid context', async () => {
    const invalidContext = null;
    
    await expect(async () => {
      await promptManager.validateTemplate(invalidContext);
    }).rejects.toThrow('Invalid template format');
  });

  test('should validate correct template', async () => {
    const validTemplate = 'valid template string';
    
    const result = await promptManager.validateTemplate(validTemplate);
    expect(result).toBe(true);
  });

  test('should handle empty search results', () => {
    const prompt = promptManager.generatePrompt('test query', []);
    expect(prompt).toContain('未找到相关搜索结果');
  });

  test('should initialize with custom system prompt', async () => {
    const customPrompt = 'custom system prompt';
    const manager = new PromptManager({ systemPrompt: customPrompt });
    
    await expect(manager.init()).resolves.not.toThrow();
    expect(manager.systemPrompt).toBe(customPrompt);
  });
}); 